package com.weibo.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.weibo.entity.Xiaobian;
import com.weibo.service.XiaobianService;
import com.weibo.util.Page;

public class XiaobianListServlet extends HttpServlet{

	public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		XiaobianService xbs = new XiaobianService();
		Page page = new Page();
		List<Object> list = xbs.findAll();//获取全部数据
		int maxPage = page.getMaxPage(list, 10);//获取最大页码		
		
		String temp = request.getParameter("page");	//获取请求页码	
		int nowPage = page.getPage(list, 10, temp);//验证页码的有效性
		
		List<Object> initList = page.getInitPage(list, nowPage, 10);//获取指定页码的数据
		
		request.setAttribute("nowPage", nowPage);//当前页
		request.setAttribute("maxPage", maxPage);//最大页
		request.setAttribute("initlist", initList);//数据
		request.setAttribute("xiaobianshu", list.size());//数据
		
		request.getRequestDispatcher("/xiaobian_list.jsp").forward(request, response);
	}

}
